package com.shopnight.controller;

import com.shopnight.entity.User;
import com.shopnight.result.ApiResult;
import com.shopnight.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/token")
@Api(tags = {"UserController"},description = "用户页面所需接口 (所有接口均带token）")
public class UserController {

    @Autowired
    UserService userService;

    @PostMapping("/updateUser")
    @ApiOperation(value = "更改用户信息",notes = "需传对应用户字段")
    public Object updateUser(@Param("参数为：userName userNick 等") @RequestBody User user){
        if (user == null)  return ApiResult.fail("请携带参数");

        if( userService.saveOrUpdate(user) ){
            return ApiResult.ok("操作成功！");
        }else {
            return ApiResult.fail("操作失败！");
        }
    }


    @PostMapping("/getUserByToken")
    @ApiOperation(value = "获取用户信息",notes = "无需传参")
    public Object getUserByToken()  {
        return userService.getUserByToken();
    }



}
